package com.itmaster;

import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.itmaster.domain.model.News;

/**
 * @author fernando.perez
 */
public class NewsAdapter extends ArrayAdapter<News> {

	private Activity context;

	public NewsAdapter(Activity context, List<News> objects) {
		super(context, 0, objects);

		this.context = context;
	}

	/**
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = context.getLayoutInflater().inflate(R.layout.news_row, null);
		}

		TextView newsTitle = (TextView) convertView.findViewById(R.id.newsTitle);
		TextView newsDescription = (TextView) convertView.findViewById(R.id.newsDescription);
		newsTitle.setText(getItem(position).getTitle());
		newsDescription.setText(getItem(position).getDescription());
		
		return convertView;
	}
}